//
//  BrrowMoneyController.m
//  DianDangDai
//
//  Created by bhf on 2017/12/14.
//  Copyright © 2017年 bhf. All rights reserved.
//

#import "BrrowMoneyController.h"
#import "BMCell.h"
#import "SDCycleScrollView.h"
@interface BrrowMoneyController () <UITableViewDelegate, UITableViewDataSource, UITextFieldDelegate,SDCycleScrollViewDelegate>
@property (nonatomic ,strong) NSArray *imgArray;
@property (nonatomic ,strong) NSArray *titleArray;
@property (nonatomic ,strong) NSArray *placeholder;
@property (nonatomic ,strong) NSArray *goodType;

@end

@implementation BrrowMoneyController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self setupViews];
    [self setUpScrollView];
    self.imgArray = @[@"a1",@"a2",@"a3",@"a4",@"a5",@"a6"];
    self.titleArray = @[@"物品类别",@"借款金额",@"借款期限",@"联系电话",@"图形码",@"验证码"];
    self.placeholder = @[@"请选择申请的物品类型",@"请输入借款金额",@"请输入1~12月内整月期限",@"请输入联系电话",@"请输入图形码",@"请输入验证码"];
    self.goodType = @[@"汽车",@"房产",@"名表",@"钢材",@"标准件",@"手机靓号",@"电子产品",@"珠宝玉石",@"红木家具",@"贵金属首饰",@"其他"];
    // Do any additional setup after loading the view.
}

- (void)setupViews {
    self.submit.layer.cornerRadius = 22;
}

//第三方轮播图
- (void)setUpScrollView {
    NSArray *imageNames = @[@"logo2.jpg",@"registerok.png",@"yaoqing.jpg",@"wintip.png",@"bolang.png"];
    // 本地加载 --- 创建不带标题的图片轮播器
    SDCycleScrollView *cycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 180) shouldInfiniteLoop:YES imageNamesGroup:imageNames];
    cycleScrollView.delegate = self;
    cycleScrollView.pageControlStyle = SDCycleScrollViewPageContolStyleClassic;
    cycleScrollView.currentPageDotColor = [UIColor colorWithHex:@"#118cf8"];
    cycleScrollView.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    cycleScrollView.autoScrollTimeInterval = 3.0;
    [self.scrollView addSubview:cycleScrollView];
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 6;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    NSString *identifier;
    
    switch (indexPath.row) {
        case 0:
            identifier = @"bm_cell_I";
            break;
        case 1:
            identifier = @"bm_cell_II";
            break;
        case 2:
            identifier = @"bm_cell_II";
            break;
        case 3:
            identifier = @"bm_cell_II";
            break;
        case 4:
            identifier = @"bm_cell_III";
            break;
        case 5:
            identifier = @"bm_cell_III";
            break;
        default:
            break;
    }
    
    BMCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier forIndexPath:indexPath];
    cell.textField.delegate = self;
    cell.image.image = [UIImage imageNamed:_imgArray[indexPath.row]];
    cell.name.text = _titleArray[indexPath.row];
    cell.textField.placeholder = _placeholder[indexPath.row];
    cell.textField.tag = indexPath.row+100;
    switch (indexPath.row) {
        case 1:
            cell.label.text = @"元";
            cell.textField.keyboardType = UIKeyboardTypeNumberPad;
            break;
        case 2:
            cell.label.text = @"月";
            cell.textField.keyboardType = UIKeyboardTypeNumberPad;
            break;
        case 3:
            cell.label.hidden = YES;
            cell.textField.keyboardType = UIKeyboardTypeNumberPad;
            break;
        default:
            break;
    }
    if (indexPath.row == 4) {
        [cell.button setTitle:@"图形码" forState:UIControlStateNormal];
     
    }
    return cell;
}
#pragma mark - TextField Delegate

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
    if (textField.tag == 100) {
        UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
        for (NSString *title in _goodType) {
            UIAlertAction *action = [UIAlertAction actionWithTitle:title style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                textField.text = action.title;
            }];
            [alert addAction:action];
        }
        UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
            
        }];
        [alert addAction:cancel];
        [self presentViewController:alert animated:YES completion:nil];
        return NO;
    } else {
        return YES;
    }
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return (SCREEN_HEIGHT-314)/6;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
